package com.hotec.PROJECT_NAME.utils;

import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * Created by zp666 on 2022/8/18.
 */
public class UtilsLock {
    public static boolean getLock (String lockName){
        StringRedisTemplate stringRedisTemplate = UtilsSpring.getBean(StringRedisTemplate.class);
        return stringRedisTemplate.opsForValue().setIfAbsent(lockName, String.valueOf(System.currentTimeMillis()), 20,TimeUnit.SECONDS);
    }

    public static void clearLock (String lockName){
        StringRedisTemplate stringRedisTemplate = UtilsSpring.getBean(StringRedisTemplate.class);
        stringRedisTemplate.delete(lockName);
    }
}
